package org.module.ui
{
	import flash.display.MovieClip;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.geom.Point;
	import flash.system.Capabilities;
	import flash.system.TouchscreenType;
	import flash.utils.getDefinitionByName;
	
	import gs.TweenLite;
	import gs.easing.*;
	
	import org.core.AbcView;
	import org.manager.GlobalManager;

	public class PopUpBase extends AbcView
	{
		/**
		 *退出事件 
		 */		
		public const exitEvent:String="PopUpBaseExit"
		
		/**
		 *动态弹出/退出效果 
		 */			
		public var ease:Boolean=false
		/**
		 *背景遮照 
		 */			
		public var back:Sprite
		
			
		public function PopUpBase()
		{
			super()
		}

		/**
		 *  初始化
		 * @return 
		 * 
		 */		
		override protected function init():void{

		}
		
		
		/**
		 *pop尺寸改变时，手动修改pop全屏布局 
		 * 
		 */		
		public function changePostion():void{
			
			//适应全屏布局：（pop中背景尺寸改变） 			
			//var scal:Number=(this.stage.stageWidth/this.stage.stageHeight)>(800/600)?this.stage.stageHeight/600:this.stage.stageWidth/800
			this.x=(stage.stageWidth-this.getWidth())/2
			this.y=(stage.stageHeight-this.getHeight())/2
			
		}
		
		
		
		
					
		/**
		 * 显示一个临时的背景遮罩在对象后面作为遮挡，并会和对象一起被删除
		 */
		public  function createBg():void
		{
			var color:uint = 0x0
			var alpha:Number = 0.6

			//背景遮罩
			back=back||new Sprite();	
			
			back.graphics.clear()	
			back.graphics.beginFill(color,alpha);
			back.graphics.drawRect(0,0,stage.stageWidth,stage.stageHeight);
			back.graphics.endFill();

			parent.addChild(back);
			
			parent.addChild(this)

		}

		/**
		 * 添加对象到显示列表事件
		 * @param e
		 * 
		 */		
		override protected function addStageEvent(e:Event):void{
			
			super.addStageEvent(e)
				
			var names:Array=getPropertyName(this, /^btn_/)
			
			for(var i:int=0;i<names.length;i++){
				
				var childname:String=names[i]

				this[childname].addEventListener(MouseEvent.MOUSE_OVER,curreMouseEvent)
					
				this[childname].addEventListener(MouseEvent.MOUSE_OUT,curreMouseEvent)
					
				this[childname].addEventListener(MouseEvent.CLICK,curreMouseEvent)
				
			}
				
		}
		
		/**
		 * 对象从显示列表中删除 
		 * @param e
		 * 
		 */		
		override protected function removeStageEvent(e:Event):void{
			
			super.removeStageEvent(e)
				
			// todo InstanceUtil.cleanObj(back);
				
			var names:Array=getPropertyName(this, /^btn_/)
			
			for(var i:int=0;i<names.length;i++){
				
				var childname:String=names[i]
				
				this[childname].removeEventListener(MouseEvent.MOUSE_OVER,curreMouseEvent)
				
				this[childname].removeEventListener(MouseEvent.MOUSE_OUT,curreMouseEvent)
					
				this[childname].removeEventListener(MouseEvent.CLICK,curreMouseEvent)
				
			}
			
			stopAllChild(this)
				
		}
		
		/**
		 * 停止对象内所有播放的动画
		 * @param item
		 * 
		 */		
		protected function stopAllChild(item:MovieClip):void{
		
			for(var i:int=0;i<item.numChildren;i++){
				
				var child:MovieClip=item.getChildAt(i) as MovieClip
					
				if(child){child.stop();stopAllChild(child)}
				
			}
		
		}
		
		protected function curreMouseEvent(e:MouseEvent):void{
			
		}
		
		private function moveComplete():void{
			
		}
		
		public function off():void{
			
		}
		
		public function on():void{
			
		}
		
	}
}